/**
 * @ Discription:获取综合评价的表格数据
 * @Autor ：liuhongjun
 * @param quotaCode
 * @param monitorType
 * @param callback
 * @returns any ywcCommonPerf.js 2017年6月7日上午10:50:25
 */
function getTableData(quotaCode, monitorType, callback) {
    var map = drgUI.setAjaxData(tabId);
    map.monitorType = monitorType;
    map.quotaCode = quotaCode;
    map.isGetCc = '0';
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc", map).done(function (res) {
        var data = [];
        if (res != undefined) {
            data = res.data;// 请求成功时处理
            callback(data);
        }
    });
}

/**
 * 获取全院的综合得分
 * @param quotaCode
 * @param monitorType
 * @returns
 */
function getHospScore(quotaCode, monitorType, getHospScoreData) {
    var map = drgUI.setAjaxData(tabId);
    map.monitorType = monitorType;
    map.quotaCode = quotaCode;
    map.isGetCc = '0';
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc", map).done(function (res) {
        var data = [];
        if (res != undefined) {
            data = res.data;//请求成功时处理
        }
        getHospScoreData(data);
    });
}

/**
 *
 * @author ：LiuHongjun
 * @any
 * @Discription:是否钻取
 * @ywcCommonPerf.js
 */
function toNextLayerBoolPerf(monitorType) {
    var bool = false;
    switch (monitorType) {
        case "depGroup":
            if (commonLayerConfig.length >= 4
                && (commonLayerConfig[1] == '1' || commonLayerConfig[2] == '1')) {
                bool = true;
            }
            break;
        case "dep":
            if (commonLayerConfig.length >= 4 && commonLayerConfig[2] == '1') {
                bool = true;
            }
            break;
    }
    return bool;
}

//查询数组a中键为key中包含数据b中键为key的次数
array_containsCnt = function (a, b, key) {
    var cnt = 0;
    for (i = 0; i < a.length; i++) {
        if (a[i][key] == b[key]) {
            cnt = cnt + 1;
        }
    }
    return cnt;
};

/**
 *
 * @ Discription:绘制雷达图
 * @Autor ：liuhongjun
 * @param sx
 * @param totalQuota
 * @param monitorType
 * @param type
 * @returns
 * any
 * ywcCommonPerf.js
 * 2017年6月7日上午11:23:40
 */
function drawRadar(totalQuota, monitorType, type) {
    var monitorName = "";
    if (monitorType == "depGroup") {
        monitorName = "科室组";
    } else if (monitorType == "dep") {
        monitorName = "科室";
    } else if (monitorType == "ward") {
        monitorName = "病区";
    } else if (monitorType == "protomedicus") {
        monitorName = "主任/副主任医师";
    } else if (monitorType == "clinic") {
        monitorName = "主诊组";
    } else if (monitorType == "resident") {
        monitorName = "住院医师";
    } else if (monitorType == "physician") {
        monitorName = "主治医师";
    }
    var titleName = "指标比较";
    var allCompareObj = [];// 选中的比较对象
    if (type) {
        ywcDGDoctorPerfDialog.find('input[name="selectedObj"]').each(
            function () {
                allCompareObj.push({
                    code: $(this).val(),
                    val: $(this).attr("descval")
                });
            });
    } else {
        $('#' + tabId + ' input[name="' + monitorType + 'code"]:checked').each(
            function () {
                allCompareObj.push({
                    code: $(this).val(),
                    val: $(this).attr("descval")
                });
            });
    }
    // 拼表格
    var id = 'id' + new Date().getTime();
    var quotaData = [];// 存放各指标的代码，描述，值
    var lines = [];
    var ajaxCount = 0;
    for (var i = 0; i < allCompareObj.length; i++) {
        var lineDesc = allCompareObj[i].val;
        var lineCode = allCompareObj[i].code;
        var paramTemp = jQuery.extend(true, {}, paramTabPage[tabId]);
        // 获取全院均值和各分析对象的指标数据
        if (allCompareObj[i].code == "hspstd") {
            paramTemp.compareType = "hosp";// 查全院均值
            paramTemp.pardepgroupCode = "";
            // 获取全院均值计算(回调)
            loadAvgHospQuotas(monitorType, paramTemp, lineCode, lineDesc,
                function (result, lineCode, lineDesc) {
                    if (result) {
                        var line = {
                            "index": 0,
                            "code": lineCode,
                            "desc": lineDesc,
                            "data": [],
                            dataShowValue: []
                        };
                        result.index = 0;
                        quotaData.push(result);
                        lines.push(line);// 拼蛛网图数据

                    }
                    ajaxCount++;
                });
        } else {
            paramTemp.compareType = "nothosp";// 非全院均值
            if (monitorType == "depGroup") {
                paramTemp.pardepgroupCode = allCompareObj[i].code;
            } else if (monitorType == "dep") {
                paramTemp.pardepCode = allCompareObj[i].code;
            } else if (monitorType == "ward") {
                paramTemp.parwardCode = allCompareObj[i].code;
            } else if (monitorType == "protomedicus") {
                paramTemp.pargroupName = "";
                paramTemp.resident = "";
                paramTemp.physician = "";
                paramTemp.protomedicus = (allCompareObj[i].code != "未入组"
                    ? allCompareObj[i].code
                    : "");
            } else if (monitorType == "clinic") {
                paramTemp.protomedicus = "";
                paramTemp.resident = "";
                paramTemp.physician = "";
                paramTemp.pargroupName = (allCompareObj[i].code != "未入组"
                    ? allCompareObj[i].code
                    : "");
            } else if (monitorType == "resident") {
                paramTemp.protomedicus = "";
                paramTemp.pargroupName = "";
                paramTemp.physician = "";
                paramTemp.resident = (allCompareObj[i].code != "未入组"
                    ? allCompareObj[i].code
                    : "");
            } else if (monitorType == "physician") {
                paramTemp.protomedicus = "";
                paramTemp.resident = "";
                paramTemp.pargroupName = "";
                paramTemp.physician = (allCompareObj[i].code != "未入组"
                    ? allCompareObj[i].code
                    : "");
            }
            loadAllQuotas(monitorType, paramTemp, lineCode, lineDesc, i,
                function (result, lineCode, lineDesc, i) {
                    if (result) {
                        var line = {
                            "index": i,
                            "code": lineCode,
                            "desc": lineDesc,
                            "data": [],
                            dataShowValue: []
                        };
                        result.index = i;
                        quotaData.push(result);
                        lines.push(line);// 拼蛛网图数据
                    }
                    ajaxCount++;
                });
        }
    }
    // 等待数据返回
    var timer = setInterval(function () {
        lines.sort(function (a, b) {
            return a.index > b.index;
        })
        quotaData.sort(function (a, b) {
            return a.index > b.index;
        })
        // 数据构造完以后画图
        if (ajaxCount === allCompareObj.length) {
            clearInterval(timer);
            var quotas = [];
            // 循环获取各指标的最大值
            for (var o in totalQuota) {
                var quotaTypes = totalQuota[o].data;
                for (var o in quotaTypes) {
                    var quota1 = quotaTypes[o];
                    for (var o1 in quota1.data) {
                        var quota = quota1.data[o1];
                        var maxValue = 0;
                        // 循环上面压入的指标代码，描述，值
                        for (var o2 in quotaData) {
                            //添加要显示的值
                            quotaData[o2][quota.quotaCode+'ShowValue'] = quotaData[o2][quota.quotaCode];
                            //负向指标转正向指标
                            if ('TimeEff,FeeEff,Risk1Ratio,Risk2Ratio,DeadRatio,DeadCaseCnt,DrugRatio'.indexOf(quota.quotaCode) > -1) {
                                //负向指标为0时加1，避免出现无穷大
                                var quotaValue = quotaData[o2][quota.quotaCode]==0?1:quotaData[o2][quota.quotaCode];
                                //console.log(quotaValue);
                                quotaData[o2][quota.quotaCode] = 1*100/quotaValue;
                                //console.log(quotaValue);
                            }
                            var value = Number(quotaData[o2][quota.quotaCode]);
                            if (value > maxValue) {
                                maxValue = value;
                            }
                        }
                        var quotaName = {
                            name: quota.quotaName,
                            code: quota.quotaCode,
                            max: Math.ceil(maxValue)
                        };
                        quotas.push(quotaName);
                    }
                }
            }
            var chartParams = {
                tooltips:{
                    position:[3,3],//固定tooltip的位置
                    formatter: function (params) {
                        var str = params.name + ': <br/>';
                        for(var o1 in quotas){
                            str += quotas[o1].name +': ' + params.data.showValue[o1] +'<br/>';
                        }
                        return str;
                    }
                }
            };
            radarCharts($("#" + tabId + " #certain" + monitorType + "PerfChart"), lines, quotaData, quotas, titleName, monitorName,chartParams);
        }
    }, 200);
}

//绘制指标复选框
function loadQuotaCheckbox(monitorType){
    var monitorTypeId = '';
    if (monitorType){
        monitorTypeId = '#'+monitorType;
    }
    var allQuota = {};
    var quotaPanel = $('#' + tabId + ' '+monitorTypeId+ ' #quotaPanel');
    //输出所有指标复选框
    if (perfQuotaDrg) {
        perfQuotaDrg.forEach(function (v) {
            v.data.forEach(function (v) {
                v.data.forEach(function (v) {
                    allQuota[v.quotaCode] = v;
                    var checked = v.selected?'checked':'';
                    quotaPanel.append('<label><input type="checkbox" value="' + v.quotaCode + '" '+checked+'/>' + v.quotaName + '</label>');
                });
            });
        });
    }
    if (perfQuotaReg) {
        perfQuotaReg.forEach(function (v) {
            v.data.forEach(function (v) {
                v.data.forEach(function (v) {
                    allQuota[v.quotaCode] = v;
                    var checked = v.selected?'checked':'';
                    quotaPanel.append('<label><input type="checkbox" value="' + v.quotaCode + '" '+checked+'/>' + v.quotaName + '</label>');
                });
            });
        });
    }
    paramTabPage[tabId]['allQuota'] = allQuota;
}

//根据选择的指标绘制雷达图
function drawRadarBySelectedQuota(monitorType) {
    var selectedQuota = [{
        data: [{
            data: []
        }]
    }];
    $('#' + tabId + ' #'+monitorType+' #quotaPanel input[type="checkbox"]:checked').each(function (i, v) {
        selectedQuota[0].data[0].data.push(paramTabPage[tabId].allQuota[v.value]);
    });
    drawRadar(selectedQuota, monitorType);
}

/**
 *
 * @ Discription:获取雷达图和下表数据
 * @Autor ：liuhongjun
 * @param monitorType
 * @param paramTemp
 * @param linedesc
 * @param callback
 * @returns
 * any
 * ywcCommonPerf.js
 * 2017年6月7日下午1:47:06
 */
function loadAllQuotas(monitorType, paramTemp, linecode, linedesc, i, callback) {
    var map = jQuery.extend(true, {}, paramTemp);
    map.monitorType = monitorType;
    map.quotaCode = "PerfQuota";
    map.isGetCc = '0';
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc",
        map).done(function (res) {
        var data = [];
        if (res.success && res.data) {
            if (res != undefined) {
                data = res.data[0];// 请求成功时处理
            }
            callback(data, linecode, linedesc, i);
        }
    });
}

/**
 * @ Discription:获取院内均值
 * @Autor ：liuhongjun
 * @param monitorType
 * @param paramTemp
 * @param linedesc
 * @param callback
 * @returns any ywcCommonPerf.js 2017年6月9日上午10:43:29
 */
function loadAvgHospQuotas(monitorType, paramTemp, linecode, linedesc, callback) {
    var map = jQuery.extend(true, {}, paramTemp);
    map.monitorType = monitorType;
    map.quotaCode = "PerfQuota";
    map.isGetCc = '0';
    $.post(contextPath + "/DrgsIndexCal/avgHospIndexCal.dhc",
        map).done(function (res) {
        var data = [];
        if (res.success && res.data) {
            if (res != undefined) {
                data = res.data[0];// 请求成功时处理
            }
            callback(data, linecode, linedesc);
        }
    });
}

//较比较对象差指标项汇总表
function medAffHspPerfJoinMinStr(table) {
    var bigBetterCode = ['CMI', 'DRGCount', 'TotalCaseCnt', 'TotalWeight', 'WeightPerBed'];
    var bigBetterName = ["CMI", "DRGs组数", "出院病例数", "总权重", "每床日权重"];
    var smallBetterCode = ['TimeEff', 'AvgFee', 'FeeEff', 'Risk1Ratio', 'Risk2Ratio'];
    var smallBetterName = ["时间消耗指数", "次均费用(元)", "费用消耗指数", "低风险死亡率(%)", "中低风险死亡率(%)"];

    var str = "";//结果字符串
    var tmpstr = "";//临时字符串
    var targetval = 0, tmpval = 0;//targetval目标科室组的某一指标值  tmpval其他科室组对应的指标值
    var addbool = true;//是否将这一指标的信息添加到表格中
    for (var i = 0; i < bigBetterCode.length; i++) {
        addbool = true;//默认添加|当有一值大于目标值时不添加
        tmpstr = "";//清空临时字符串
        tmpstr += "<tr><td>" + bigBetterName[i] + "</td>";//添加指标名称
        targetval = table[0][bigBetterCode[i]] == null ? 0 : table[0][bigBetterCode[i]];//获取目标科室组的某一指标值
        tmpstr += "<td>" + targetval + "</td>";//添加目标科室组的某一指标值
        for (var j = 1; j < table.length; j++) {
            tmpval = table[j][bigBetterCode[i]] == null ? 0 : table[j][bigBetterCode[i]];//获取其他科室组的某一指标值
            if (Number(targetval) >= Number(tmpval)) {
                addbool = false;
                break;
            }
            tmpstr += "<td>" + tmpval + "</td>";//添加其他科室组的某一指标值
        }
        if (addbool) {
            tmpstr += "</tr>"
            str += tmpstr;
        }
    }

    for (var i = 0; i < smallBetterCode.length; i++) {
        addbool = true;//默认添加|当有一值大于目标值时不添加
        tmpstr = "";//清空临时字符串
        tmpstr += "<tr><td>" + smallBetterName[i] + "</td>";//添加指标名称
        targetval = table[0][smallBetterCode[i]] == null ? 0 : table[0][smallBetterCode[i]];//获取目标科室组的某一指标值
        tmpstr += "<td>" + targetval + "</td>";//添加目标科室组的某一指标值
        for (var j = 1; j < table.length; j++) {
            tmpval = table[j][smallBetterCode[i]] == null ? 0 : table[j][smallBetterCode[i]];//获取其他科室组的某一指标值
            if (Number(targetval) <= Number(tmpval)) {
                addbool = false;
                break;
            }
            tmpstr += "<td>" + tmpval + "</td>";//添加其他科室组的某一指标值
        }
        if (addbool) {
            tmpstr += "</tr>"
            str += tmpstr;
        }
    }

    if ("" == str) {
        str += "<tr>"
        for (var j = -1; j < table.length; j++) {

            str += "<td>无数据</td>";//添加其他科室组的某一指标值
        }
        str += "</tr>"
    }
    return str;
}

/**
 * @param {} totalQuota
 * @param {} monitorType
 * @param {} functionName
 * @param {} perfQuota
 * @param {} perfQuota_1
 * 加载绩效分析最下面表格
 */
function loadTotalQuotaTable(totalQuota, monitorType, functionName, perfQuota, perfQuota_1) {
    paramTabPage[tabId].totalQuota = totalQuota;
    var monitorName = "";
    var results = [];
    var quotasAll = [];
    var quotaCode = "PerfQuota";
    if (monitorType == "depGroup") {
        monitorName = "科室组";
    } else if (monitorType == "dep") {
        monitorName = "科室";
    } else if (monitorType == "ward") {
        monitorName = "病区";
    } else if (monitorType == "protomedicus") {
        monitorName = "主任/副主任医师";
    } else if (monitorType == "clinic") {
        monitorName = "主诊组";
    } else if (monitorType == "resident") {
        monitorName = "住院医师";
    } else if (monitorType == "physician") {
        monitorName = "主治医师";
    }
    var map = drgUI.setAjaxData(tabId);
    map.monitorType = monitorType;
    map.quotaCode = quotaCode;
    map.isGetCc = '0';
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc", map).done(function (res) {
        var data = [];
        if (res != undefined) {
            data = res.data;//请求成功时处理
        }
        var str = '';
        var columns = [];
        var sth = "";
        if (monitorType == "protomedicus" || monitorType == "clinic" || monitorType == "resident" || monitorType == "physician") {
            if (!((paramTabPage[tabId].upOnLevel == 'dep' && paramTabPage[tabId].isA == 0) || (paramTabPage[tabId].upOnLevel == 'ward'))) {
                columns.push({
                    "data": null,
                    "defaultContent": '',
                    "className": 'details-control',
                    "width": '30px'
                });
                sth = '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending" width="100px"></th> ';
                sth += '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending" width="100px">' + monitorName + '</th> ';
            } else {
                sth = '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending" width="100px">' + monitorName + '</th> ';

            }
        } else {
            sth = '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending" width="100px">' + monitorName + '</th> ';
        }
        columns.push({
            "data": "depGroup", "render": function (obj, type, full) {
                if (toNextLayerBoolPerf(monitorType)) {
                    return "<a title ='" + full.ccode + "' href=\"javascript:" + functionName + "('" + full.ccode + "','" + full.ddesc + "') \">" + full.ddesc + "</a>";
                } else {
                    if (full.isBelongTo == false) {
                        return "<span data-toggle=\"tooltip\" data-placement=\"right\" title=\"" + full.currentDepName + "\"><font color=\"red\">" + full.ddesc + "</font></span>";
                    } else {
                        return full.ddesc != null ? full.ddesc : "未入组";
                    }
                    return full.ddesc != null ? full.ddesc : "未入组";
                }
            }
        });
        str += '<table id="' + monitorType + 'totalQuotas-table' + tabId + '" class="table table-striped" cellspacing="0" width="100%" role="grid" aria-describedby="example_info"> ';
        str += '    <caption class="contaotalsccq">' + monitorName + 'DRG指标综合比较汇总表</caption> ';
        str += '    <thead> ';
        str += '    <tr> </tr> ';
        str += '    </thead> ';
        str += '    <tbody></tbody> ';
        str += '</table> ';
        var ajaxCount1 = 0;
        for (var o in totalQuota) {
            var QuotaCode = totalQuota[o].data;
            for (var o in QuotaCode) {
                var quotas = QuotaCode[o];
                quotasAll.push(quotas.data);
                for (var o1 in quotas.data) {
                    ajaxCount1++;
                    var quota = quotas.data[o1];
                    var quotaCode = quota.quotaCode;
                    var quotaName = quota.quotaName;
                    var isLink = quota.isLink;
                    col(quotaCode, quotaName, isLink);
                }
            }
        }

        function col(quotaCode, quotaName, isLink) {
            if (isLink == "1") {
                column = {
                    "data": null,
                    "sType": "number-html",
                    "render": function (obj, type, full) {
                        if (full[quotaCode] > 0) {
                            return "<a href=\"javascript:loadCaseDtl('" + full.ddesc + "|" + quotaName + "|" + "','" + full.ccode + "','" + monitorType + "', '" + quotaCode + "')\">" + formatNumber(full[quotaCode]) + "</a>"
                        } else {
                            return full[quotaCode];
                        }
                    }
                };
            } else {
                column = {
                    "data": quotaCode,
                    "sType": "number-html",
                    "render": function (obj, type, full) {
                        return "<span>" + formatNumber(full[quotaCode]) + "</span>"
                    }
                };
            }
            sth += '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1">' + quotaName + '</th> ';
            columns.push(column);
            ajaxCount1--;
        }

        var timerId = window.setInterval(function () {
            if (ajaxCount1 == 0) {
                window.clearInterval(timerId);
                sth += '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1">操作</th> ';
                column = {
                    "data": "OPERATION",
                    "render": function (obj, type, full) {
                        return "<a title='趋势' href=\"javascript:trendPerf('1','" + full.ccode + "', '" + full.ddesc + "', '" + monitorType + "')\" class='trend-link'><i class='fa fa-line-chart'></i></a>";
                    }
                }
                columns.push(column);
                $("#" + tabId + " #" + monitorType + "totalQuotasTable").html(str);
                $("#" + tabId + " #" + monitorType + "totalQuotas-table" + tabId + " thead tr").html(sth);
                if (data[0] && data[0].ddesc == undefined) {
                    var length = totalQuota[0].data[0].data.length + 2;
                    $("#" + tabId + " #" + monitorType + "totalQuotas-table" + tabId + " tbody").html("<tr><td colspan='" + length + "' align='center'>表格中没有可用数据<td></tr>")
                } else {
                    var paramsDataTables = {
                        order: [],
                        lengthChange: false,
                        info: false,
                        columnDefs: [{"orderable": false, "targets": [columns.length - 1]}]
                    };
                    var drawCallback = function (oSettings) { //table加载完成后回调事件
                        $("[data-toggle='tooltip']").tooltip();
                    }
                    paramsDataTables.drawCallback = drawCallback;
                    if (columns[0] ["className"] == 'details-control') {
                        paramsDataTables.columnDefs.push({"orderable": false, "targets": [0]});
                    }
                    var oaTable = null;
                    $.when(isBelongToDep(monitorType, data)).done(function () {
                        oaTable = $("#" + tabId + " #" + monitorType + "totalQuotas-table" + tabId).dataTableBasic(columns, data, paramsDataTables);
                    })

//					 var oaTable=$("#"+tabId+" #"+monitorType+"totalQuotas-table"+tabId).dataTableBasic(columns,data,paramsDataTables);				 
                    /**
                     * 点击+展开详情
                     */
                    if (monitorType == "protomedicus" || monitorType == "pargroupName" || monitorType == "resident" || monitorType == "physician") {
                        if (!((paramTabPage[tabId].upOnLevel == 'dep' && paramTabPage[tabId].isA == 0) || (paramTabPage[tabId].upOnLevel == 'ward'))) {
                            var cloumsData = totalQuota[0].data[0].data;
                            var ota;
                            $("#" + tabId + " #" + monitorType + "totalQuotas-table" + tabId).find("tbody").off("click", "td.details-control");
                            $("#" + tabId + " #" + monitorType + "totalQuotas-table" + tabId).find("tbody").on('click', 'td.details-control', function () {
                                var nTr = $(this).closest('tr');
                                var row = oaTable.row(nTr);
                                var aData = row.data();
                                if (row.child.isShown()) {//判断是否已打开
                                    row.child.hide();
                                    nTr.removeClass("shown");
                                } else {
                                    var cloumStr = [{
                                        "title": "科室",
                                        "data": "ddesc"
                                    }];
                                    var qoutaCodes = [];
                                    for (var i in cloumsData) {
                                        cloumStr.push({
                                            "title": cloumsData[i].quotaName,
                                            "data": cloumsData[i].quotaCode
                                        });
                                        qoutaCodes.push(cloumsData[i].quotaCode);
                                    }
                                    nTr.addClass("shown");
                                    var data = [];
                                    var doctor_code = aData.ccode;
                                    var onUpLevel = "";
                                    if (paramTabPage[tabId].upOnLevel == 'depGroup') {
                                        onUpLevel = 'dep';
                                    } else if (paramTabPage[tabId].upOnLevel == 'dep' && paramTabPage[tabId].isA == '1') {
                                        onUpLevel = 'ward';
                                    }
                                    findDoctorQuota(monitorType, onUpLevel, doctor_code, qoutaCodes, function (data) {
                                        //获取要查询的关联指标的指标代码
                                        try {
                                            if (ota != undefined) {
                                                ota.destroy();
                                            }
                                            var doctor_code = aData.ccode;
                                            row.child("正在加载...").show();
                                            row.child('<table id="' + monitorType + doctor_code + 'totalQuotas-table" class="table"  width="100%" > </table>').show();
                                            var paramsDataTables = {
                                                order: [],
                                                searching: false,
                                                paging: false,
                                                lengthChange: false,
                                                info: false,
                                                dom: '<"top"fl>rt<"bottom"ip><"clear">',
                                                columnDefs: [{"orderable": false, "targets": [cloumStr.length - 1]}]
                                            };
                                            ota = $("#" + tabId + " #" + monitorType + doctor_code + "totalQuotas-table").dataTableBasic(cloumStr, data, paramsDataTables);
                                        } catch (e) {
                                            console.log(e)
                                            row.child("出错了...").show();
                                        }
                                    });
                                }
                            });
                        }

                    }
                }
            }
        }, 1000);
    });
}

/**
 * @param code
 * @param desc
 * @param monitorType
 * @returns加载医生比较分析页面
 */
function loadHospDoctor(code, desc, monitorType, isA) {
    var param = jQuery.extend(true, {}, paramTabPage[tabId]);
    param.upOnLevel = monitorType;
    param.isA = isA;
    if (monitorType == "depGroup") {
        param.depGroupCode = code;
        openTab('/pages/yizheng/perf/ywcDGDoctorPerf.jsp', desc + "|" + '医生比较', 'performanceDoctor' + code, 'performanceDoctor' + code, param);
    } else if (monitorType == "dep") {
        param.depCode = code;
        openTab('/pages/yizheng/perf/ywcDGDoctorPerf.jsp', desc + "|" + '医生比较', 'performanceDoctor' + code, 'performanceDoctor' + code, param);
    } else if (monitorType == "ward") {
        param.wardCode = code;
        openTab('/pages/yizheng/perf/ywcDGDoctorPerf.jsp', desc + "|" + '医生比较', 'Doctor' + code, 'Doctor' + code, param);
    }
}

/**
 * @param {} title标题
 * @param {} ccode//编码
 * @param {} ddesc//描述
 * @param {} monitorType//监测层级
 * 趋势图展开
 */
function trendPerf(title, ccode, ddesc, monitorType) {
    if (title == "1") {
        title = ddesc;
    }
    if (!title) title = "弹出窗口";
    var paramTemp = drgUI.setAjaxData(tabId);
    if (monitorType == "depGroup") {
        paramTemp.depGroupCode = ccode;
    } else if (monitorType == "dep") {
        paramTemp.depCode = ccode;
    } else if (monitorType == "protomedicus") {
        paramTemp.groupName = "";
        paramTemp.resident = "";
        paramTemp.physician = "";
        paramTemp.protomedicus = ccode;
    } else if (monitorType == "clinic") {
        paramTemp.protomedicus = "";
        paramTemp.resident = "";
        paramTemp.physician = "";
        paramTemp.groupName = ccode;
    } else if (monitorType == "resident") {
        paramTemp.protomedicus = "";
        paramTemp.groupName = "";
        paramTemp.physician = "";
        paramTemp.resident = ccode;
    } else if (monitorType == "physician") {
        paramTemp.protomedicus = "";
        paramTemp.resident = "";
        paramTemp.groupName = "";
        paramTemp.physician = ccode;
    }
    var mrType = paramTabPage[tabId].mrType;
    $.post(contextPath + '/pages/yizheng/perf/ywcTrendPerf.jsp').done(function (data) {
        var dialog = $(data);
        dialog.find(".modal-title").html(title + "指标趋势");
        dialog.modal({
            keyboard: false
        }).on({
            'hidden.bs.modal': function () {
                $(this).remove();
            },
            'shown.bs.modal': function () {
                var str = '';
                str += ' <div style="overflow: hidden;border-bottom: 1px solid #0a0;padding-bottom: 10px;"> ';
                str += ' 	<span id="compareTypes">比较类型:</span> ';
                str += "  <input type='checkbox' name='year' checked='checked' value='CurrentValue' descval='本期值'/>本期值&nbsp;&nbsp;";
                str += "  <input type='checkbox' name='year' value='year' descval='同期值'/>同期值&nbsp;&nbsp;";
                if (mrType == 'M') {
                    str += "  <input type='checkbox' name='year' value='month' descval='上期值'/>上期值&nbsp;&nbsp;";
                }
                str += "  <input type='checkbox' name='year' value='manage' descval='绩效值'/>绩效值&nbsp;&nbsp;";
                str += "  <input type='checkbox' name='year' value='std' descval='标杆值'/>标杆值&nbsp;&nbsp;";
                str += ' 	<a id="id1" type="button"  class="btn btn-primary"  ><span class="fa fa-arrows-alt"></span>&nbsp;比较</a> ';
                str += ' </div> ';
                str += ' <div id="tc_id" class="row"> ';
                str += ' </div> ';
                dialog.find(".echartscq").html(str);
                medAffHspPerfLoadYear(dialog, paramTemp);
                var btnClick = function () {
                    var str1 = '';
                    str1 += ' <div class=""> ';
                    str1 += ' 	<div class="col-md-6"> ';
                    str1 += ' 		<div id="certainDepGroupPerfChart-trend_1" style="width:580px;height:250px;"><img src="images/pageloading.gif"></div> ';
                    str1 += ' 	</div> ';
                    str1 += ' 	<div class="col-md-6"> ';
                    str1 += ' 		<div id="certainDepGroupPerfChart-trend_2" style="width:580px;height:250px;"><img src="images/pageloading.gif"></div> ';
                    str1 += ' 	</div> ';
                    str1 += ' </div> ';
                    str1 += ' <div class=""> ';
                    str1 += ' 	<div class="col-md-12"> ';
                    str1 += ' 		<h4 style="text-align: center;"><span style="font-size:18px;" class="depGroupDesc"></span>年度DRG指标综合比较汇总表</h4> ';
                    str1 += ' 		<div id="drgsQuotasTrend-table"><img src="images/pageloading.gif"></div> ';
                    str1 += '  </div> ';
                    str1 += ' </div> ';
                    dialog.find("#tc_id").html(str1);
                    var perfQuota = paramTemp.drg;
                    var perfQuota_1 = paramTemp.reg;
                    //修改函数compareTrend增加参数  By ruanshuli At 2017年2月16日 13:56:53
                    compareTrend(dialog, paramTemp, monitorType, '#certainDepGroupPerfChart-trend_1', 1, perfQuota, '  DRG指标比较');
                    compareTrend(dialog, paramTemp, monitorType, '#certainDepGroupPerfChart-trend_2', 2, perfQuota_1, '  常规指标比较');
                    loadTrendTotalTable(dialog, monitorType, paramTemp, ddesc);
                }
                dialog.find("#id1").unbind("click");
                dialog.find("#id1").bind("click", btnClick);
                dialog.find("#id1").click();
            }
        });
    });
}

/**
 * 趋势图时间选择
 * @param {} dialog
 * @param {} paramTemp
 */
function medAffHspPerfLoadYear(dialog, paramTemp) {
    //获取分组数据年份
    var str = "";
    $.ajax({
        url: contextPath + '/DrgsIndexCal/getGroupAllYears.dhc',
        async: false,
        dataType: "json",
        data: {
            'pardepgroupCode': paramTemp.depGroupCode,
            'pardepCode': paramTemp.depCode,
            'pargroupName': paramTemp.groupName,
            'protomedicus': paramTemp.protomedicus,
            'physician': paramTemp.physician,
            'resident': paramTemp.resident
        },
        type: "post",
        success: function (result) {
            var years = result.data;
            $.each(years, function (n, value) {
                str += '<option value="' + value + '">' + value + '年</option>';
            })
            dialog.find('#trend-year').html(str).on('change', function () {
                //清空原有的combbox,加载新的
                var val = dialog.find('#trend-year').val();
                str = "";
                dialog.find('#years').html("");
                var i = 1;
                $.each(years, function (n, value) {
                    if (value != val) {
                        if (i % 10 == 0 && i != 0) str += "<br/>";
                        str += "<input type='checkbox' name='year' id='" + value + "' value='" + value + "'/><label for='" + value + "'>" + value + "</label>&nbsp;&nbsp;";
                        i = i + 1;
                    }
                });
                dialog.find('#years').append(str);
            });
            //清空原有的combbox,加载新的
            var val = dialog.find('#trend-year').val();
            str = "";
            dialog.find('#years').html("");
            var i = 1;
            $.each(years, function (n, value) {
                if (value != val) {
                    if (i % 10 == 0 && i != 0) str += "<br/>";
                    str += "<input type='checkbox' name='year' id='" + value + "' value='" + value + "'/><label for='" + value + "'>" + value + "</label>&nbsp;&nbsp;";
                    i = i + 1;
                }
            });
            if (str == "") {
                dialog.find('#compareYears').css('display', 'none');
            }
            dialog.find('#years').append(str);
            dialog.find('#years input:first-child').click();
        }
    });

}

/**
 * @ Discription:获取趋势图回调函数
 * @Autor ：liuhongjun
 * @Date  ：2018年4月19日下午2:26:49
 */
function loadAllQuotas_1(monitorType, compareType, paramTemp, year, i, callback) {
    var outManageCodeYear = "";
    if (compareType == "manage") {
        outManageCodeYear = "manager_inner";
    } else if (compareType == "std") {
        outManageCodeYear = "std_computer";
    }
    var map = $.extend(true, {}, paramTemp);
    map.compareType = compareType;
    map.monitorType = monitorType;
    map.msCode = outManageCodeYear;
    map.isGetCc = '1';
    map.quotaCode = 'PerfQuota';
    map.parwardCode = paramTemp.wardCode;
    map.pardepCode = paramTemp.depCode;
    map.pardepgroupCode = paramTemp.depGroupCode;
    map.pargroupName = paramTemp.groupName;
    map.physician = paramTemp.physician;
    map.parresidentCode = paramTemp.resident;
    map.protomedicus = paramTemp.protomedicus;
    var result = "";
    $.ajax({
        url: contextPath + "/DrgsIndexCal/indexCal.dhc",    //请求的url地址
        dataType: "json",   //返回格式为json
        data: map,    //参数值
        type: "post",   //请求方式
        success: function (res) {
            var data = [];
            if (res != undefined) {
                data = res.data[0];//请求成功时处理
            }
            callback(data, year, i);
        }
    });
};

function compareTrend(dialog, paramTemp, monitorType, chartId, sx, demoQuota, compareName) {
    var totalQuota = paramTemp.totalQuota;
    var perfQuota = paramTemp.a;
    var perfQuota_1 = paramTemp.b;
    var years = [];
    dialog.find('input[name="year"]:checked').each(function () {
        years.push({
            code: $(this).val(),
            val: $(this).attr("descval")
        });
    });
    var str = '';
    var data = [];
    var lines = [];
    var ajaxCount = 0;
    for (var i = 0; i < years.length; i++) {
        paramTemp.mrType = "custom";
        paramTemp.mrLot = "";
        loadAllQuotas_1(monitorType, years[i].code, paramTemp, years[i], i, function (result, year, i) {
            var line = {"index": i, "code": "", "desc": years[i].val, "data": []};
            for (var o in result) {
                result.index = i;//给返回结果添加一个序号
                if (years[i].code !== "CurrentValue") {
                    if (result[o + 'cc'] !== undefined) {
                        result[o] = result[o + 'cc'];

                    } else if (typeof result[o] !== 'object' && o.indexOf('cc') === -1) {
                        result[o] = null;
                    }

                }
            }
            data.push(result);//拼表数据
            lines.push(line);//拼蛛网图数据
            str += '<td>' + year + '</td>';
            ajaxCount++;
        });
    }
    //等待数据返回
    var timer = setInterval(function () {
        data.sort(function (a, b) {//返回结果按序号排序
            return a.index > b.index;
        })
        lines.sort(function (a, b) {
            return a.index > b.index;
        })
        if (ajaxCount == years.length) {
            clearInterval(timer);
            str += '</tr></thead><tbody>';
            str += medAffHspPerfJoinMinStr(data);
            str += '</tbody></table>';
            dialog.find('#certainDepGroupPerfTable-trend').html(str);

            var quotas = [];
            for (var o in demoQuota) {
                var quotaTypes = demoQuota[o].data;
                for (var o in quotaTypes) {
                    var quota1 = quotaTypes[o];
                    for (var o1 in quota1.data) {
                        var quota = quota1.data[o1];
                        var maxValue = 0;
                        for (var o2 in data) {
                            var value = Number(data[o2][quota.quotaCode]);
                            if (value > maxValue) {
                                maxValue = value;
                            }
                        }
                        var quotaName = {name: quota.quotaName, code: quota.quotaCode, max: Math.ceil(maxValue)};
                        quotas.push(quotaName);
                    }
                }
                radarCharts(dialog.find(chartId), lines, data, quotas, compareName, "");
            }
        }
    });
}

/**
 * @ Discription:弹出框趋势图
 * @Autor ：liuhongjun
 * @Date  ：2018年4月19日下午2:25:56
 */
function loadTrendTotalTable(dialog, monitorType, paramTemp, monitorName) {

    var totalQuota = paramTemp.totalQuota;
    if (!monitorName) monitorName = "";
    var years = [];
    dialog.find('input[name="year"]:checked').each(function () {
        years.push({
            code: $(this).val(),
            val: $(this).attr("descval")
        });
    });

    var data = [];
    var ajaxCount = 0;
    for (var i = 0; i < years.length; i++) {
        paramTemp.mrType = "custom";
        paramTemp.mrLot = "";
        loadAllQuotas_1(monitorType, years[i].code, paramTemp, years[i], i, function (result, year, i) {
            if (result) {
                result.year = year;

                for (var o in result) {
                    if (years[i].code !== "CurrentValue") {
                        if (result[o + 'cc'] !== undefined) {
                            result[o] = result[o + 'cc'];

                        } else if (typeof result[o] !== 'object' && o.indexOf('cc') === -1) {
                            result[o] = '-';
                        }

                    }
                }
                data.push(result);//拼表数据
                ajaxCount++;
            }
        });
    }
    //等待数据返回
    var timer = setInterval(function () {
        if (ajaxCount == years.length) {
            clearInterval(timer);
            var str = '';
            var columns = [];
            var column = {
                "data": "year",
                "render": function (obj, type, full) {
                    return full.year.val;
                }
            };
            columns.push(column);
            str += '<table id="totalQuotas-table" class="table table-striped" cellspacing="0" width="95%" role="grid" aria-describedby="example_info"> ';
            str += '    <caption class="contaotalsccq"></caption> ';
            str += '    <thead> ';
            str += '    <tr> </tr> ';
            str += '    </thead> ';
            str += '    <tbody></tbody> ';
            str += '</table> ';
            var sth = '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending">比较类型</th> ';
            for (var o in totalQuota) {
                var QuotaCode = totalQuota[o].data;
                for (var o in QuotaCode) {
                    var quotas = QuotaCode[o];
                    for (var o1 in quotas.data) {
                        var quota = quotas.data[o1];
                        var quotaCode = quota.quotaCode;
                        var quotaName = quota.quotaName;
                        sth += '<th tabindex="0" aria-controls="example" rowspan="1" colspan="1">' + quotaName + '</th> ';
                        column = {"data": quotaCode};
                        columns.push(column);
                    }
                }
            }

            dialog.find("#drgsQuotasTrend-table").html(str);
            dialog.find("#totalQuotas-table thead tr").html(sth);
            var paramsDataTables = {lengthChange: false, info: false, tableTitle: '年度DRG指标综合比较汇总表'};
            dialog.find("#totalQuotas-table").dataTableBasic(columns, data, paramsDataTables)
        }
    });
}

function loadCaseDtl(title, ccode, monitorType, quotaCode) {
    var param = jQuery.extend(true, {}, paramTabPage[tabId]);
    param.quotaCode = quotaCode;
    if (ccode) {
        if (monitorType == "depGroup") {
            param.depGroupCode = ccode;
        } else if (monitorType == "dep") {
            param.depCode = ccode;
        } else if (monitorType == "ward") {
            param.wardCode = ccode;
        } else if (monitorType == "clinic") {
            param.groupName = ccode;
        } else if (monitorType == "protomedicus") {
            param.protomedicus = ccode;
        } else if (monitorType == "physician") {
            param.physician = ccode;
        } else if (monitorType == "resident") {
            param.parresident = ccode;
        } else if (monitorType == "mdc") {
            param.mdcCode = ccode;
        } else if (monitorType == "adrg") {
            param.adrgCode = ccode;
        } else if (monitorType == "drgs") {
            param.drgCode = ccode;
        }
    }
    openTab('/pages/drgscommon/case.jsp', title + "病例明细", "caseDtl" + monitorType + ccode, "caseDtl" + monitorType + ccode, param);
}

/**
 *
 * @param data
 * @returns获取展开数据
 */
function findDoctorQuota(monitorType, onUpLevel, doctor_code, qoutaCodes, callback) {
    var protomedicus = "";
    var clinic = "";
    var resident = "";
    var physician = "";
    if (monitorType == "protomedicus") {
        protomedicus = doctor_code;
    } else if (monitorType == "clinic") {
        clinic = doctor_code;
    } else if (monitorType == "resident") {
        resident = doctor_code;
    } else if (monitorType == "physician") {
        physician = doctor_code;
    } else {
        resident = doctor_code;
    }
    var map = drgUI.setAjaxData(tabId);
    map.monitorType = onUpLevel;
    map.quotaCode = qoutaCodes;
    map.isGetCc = '0';
    map.pargroupName = clinic;
    map.protomedicus = protomedicus;
    map.physician = physician;
    map.resident = resident;
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc", map).done(function (res) {
        var data = [];
        if (res != undefined) {
            data = res.data;//请求成功时处理
        }
        callback(data);
    });

}

/**
 * 科室组回调函数
 *
 * @param {}
 *            quotaCode
 * @param {}
 *            monitorType
 * @param {} callBack
 */
function getPerfScoreTable(quotaCode, monitorType, callBack) {
    var map = drgUI.setAjaxData(tabId);
    map.monitorType = monitorType;
    map.quotaCode = quotaCode;
    map.isGetCc = '0';
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc", map).done(function (res) {
        if (res.success) {
            data = res.data;
            callBack(quotaCode, data);
        }
    });
}

//获取科室等相关信息,用于将所在科室编码映射成描述
loadDepRelatedInfoByConfig();